.class Lcom/instagram/android/service/y;
.super Ljava/lang/Object;
.source "VideoUploader.java"


# instance fields
.field private final a:Lcom/instagram/android/d/a/a;


# direct methods
.method public constructor <init>(Lcom/instagram/android/d/a/a;)V
    .locals 0
    .parameter

    .prologue
    .line 32
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 33
    iput-object p1, p0, Lcom/instagram/android/service/y;->a:Lcom/instagram/android/d/a/a;

    .line 34
    return-void
.end method


# virtual methods
.method public a(Lcom/instagram/pendingmedia/model/c;)Lcom/instagram/android/service/aa;
    .locals 12
    .parameter

    .prologue
    const/4 v11, 0x2

    const/4 v0, 0x0

    const/4 v3, 0x0

    .line 37
    .line 43
    invoke-virtual {p1}, Lcom/instagram/pendingmedia/model/c;->A()Ljava/util/List;

    move-result-object v1

    invoke-interface {v1}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v5

    move v1, v0

    move-object v2, v3

    move v4, v0

    .line 44
    :goto_0
    invoke-interface {v5}, Ljava/util/Iterator;->hasNext()Z

    move-result v0

    if-eqz v0, :cond_b

    .line 45
    invoke-interface {v5}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/instagram/pendingmedia/model/j;

    .line 46
    const-string v6, "VideoUploader"

    new-instance v7, Ljava/lang/StringBuilder;

    invoke-direct {v7}, Ljava/lang/StringBuilder;-><init>()V

    const-string v8, "Trying server: "

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v0}, Lcom/instagram/pendingmedia/model/j;->c()Ljava/lang/String;

    move-result-object v8

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v7

    invoke-static {v6, v7}, Lcom/facebook/e/a/a;->b(Ljava/lang/String;Ljava/lang/String;)V

    .line 47
    add-int/lit8 v1, v1, 0x1

    .line 50
    :try_start_0
    new-instance v6, Lcom/instagram/android/v/a/a/a;

    invoke-virtual {v0}, Lcom/instagram/pendingmedia/model/j;->c()Ljava/lang/String;

    move-result-object v7

    invoke-virtual {v0}, Lcom/instagram/pendingmedia/model/j;->b()Ljava/lang/String;

    move-result-object v0

    invoke-direct {v6, p1, v7, v0}, Lcom/instagram/android/v/a/a/a;-><init>(Lcom/instagram/pendingmedia/model/c;Ljava/lang/String;Ljava/lang/String;)V

    .line 52
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v7

    .line 53
    iget-object v0, p0, Lcom/instagram/android/service/y;->a:Lcom/instagram/android/d/a/a;

    new-instance v9, Lcom/instagram/android/service/z;

    invoke-direct {v9, p0, p1}, Lcom/instagram/android/service/z;-><init>(Lcom/instagram/android/service/y;Lcom/instagram/pendingmedia/model/c;)V

    invoke-virtual {v0, v6, v9}, Lcom/instagram/android/d/a/a;->a(Lcom/instagram/android/d/c/g;Lcom/instagram/android/d/f/i;)Lch/boye/httpclientandroidlib/HttpResponse;

    move-result-object v2

    .line 60
    const-string v0, "VideoUploader"

    new-instance v6, Ljava/lang/StringBuilder;

    invoke-direct {v6}, Ljava/lang/StringBuilder;-><init>()V

    const-string v9, "Time to upload "

    invoke-virtual {v6, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v9

    sub-long v7, v9, v7

    long-to-double v7, v7

    const-wide v9, 0x408f400000000000L

    div-double/2addr v7, v9

    invoke-virtual {v6, v7, v8}, Ljava/lang/StringBuilder;->append(D)Ljava/lang/StringBuilder;

    move-result-object v6

    const-string v7, "s"

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-static {v0, v6}, Lcom/facebook/e/a/a;->b(Ljava/lang/String;Ljava/lang/String;)V

    .line 62
    if-nez v2, :cond_4

    .line 63
    const-string v0, "VideoUploader"

    const-string v6, "Timed out waiting for server response on upload video."

    invoke-static {v0, v6}, Lcom/facebook/e/a/a;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 65
    if-nez v4, :cond_2

    .line 66
    new-instance v0, Lcom/instagram/android/d/g/e;

    invoke-direct {v0}, Lcom/instagram/android/d/g/e;-><init>()V

    .line 67
    iget-object v4, p0, Lcom/instagram/android/service/y;->a:Lcom/instagram/android/d/a/a;

    invoke-virtual {v4, v0}, Lcom/instagram/android/d/a/a;->a(Lcom/instagram/android/d/c/g;)Lch/boye/httpclientandroidlib/HttpResponse;

    move-result-object v0

    .line 68
    if-nez v0, :cond_1

    .line 69
    const-string v0, "VideoUploader"

    const-string v1, "No connectivity, failing."

    invoke-static {v0, v1}, Lcom/facebook/e/a/a;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 70
    sget-object v0, Lcom/instagram/android/service/aa;->c:Lcom/instagram/android/service/aa;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 130
    if-eqz v2, :cond_0

    .line 132
    :try_start_1
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getEntity()Lch/boye/httpclientandroidlib/HttpEntity;

    move-result-object v1

    invoke-static {v1}, Lch/boye/httpclientandroidlib/util/EntityUtils;->consume(Lch/boye/httpclientandroidlib/HttpEntity;)V
    :try_end_1
    .catch Ljava/io/IOException; {:try_start_1 .. :try_end_1} :catch_7

    .line 143
    :cond_0
    :goto_1
    return-object v0

    .line 72
    :cond_1
    const/4 v4, 0x1

    .line 76
    :cond_2
    :try_start_2
    const-string v0, "VideoUploader"

    const-string v6, "Have connectivity, trying next server"

    invoke-static {v0, v6}, Lcom/facebook/e/a/a;->e(Ljava/lang/String;Ljava/lang/String;)V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    move v0, v4

    .line 130
    :goto_2
    if-eqz v2, :cond_3

    .line 132
    :try_start_3
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getEntity()Lch/boye/httpclientandroidlib/HttpEntity;

    move-result-object v4

    invoke-static {v4}, Lch/boye/httpclientandroidlib/util/EntityUtils;->consume(Lch/boye/httpclientandroidlib/HttpEntity;)V
    :try_end_3
    .catch Ljava/io/IOException; {:try_start_3 .. :try_end_3} :catch_6

    :cond_3
    :goto_3
    move v4, v0

    .line 137
    goto/16 :goto_0

    .line 78
    :cond_4
    :try_start_4
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getStatusLine()Lch/boye/httpclientandroidlib/StatusLine;

    move-result-object v0

    if-nez v0, :cond_5

    .line 79
    const-string v0, "VideoUploader"

    const-string v6, "Bad response from server on upload video, retrying new server."

    invoke-static {v0, v6}, Lcom/facebook/e/a/a;->e(Ljava/lang/String;Ljava/lang/String;)V

    move v0, v4

    goto :goto_2

    .line 81
    :cond_5
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getStatusLine()Lch/boye/httpclientandroidlib/StatusLine;

    move-result-object v0

    invoke-interface {v0}, Lch/boye/httpclientandroidlib/StatusLine;->getStatusCode()I

    move-result v0

    const/16 v6, 0xc8

    if-ne v0, v6, :cond_6

    .line 82
    const-string v0, "VideoUploader"

    const-string v1, "Video upload success!"

    invoke-static {v0, v1}, Lcom/facebook/e/a/a;->b(Ljava/lang/String;Ljava/lang/String;)V

    .line 83
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getEntity()Lch/boye/httpclientandroidlib/HttpEntity;

    move-result-object v0

    invoke-static {v0}, Lch/boye/httpclientandroidlib/util/EntityUtils;->toString(Lch/boye/httpclientandroidlib/HttpEntity;)Ljava/lang/String;

    move-result-object v0

    .line 84
    invoke-static {}, Lcom/instagram/android/service/f;->a()Lcom/instagram/android/service/f;

    move-result-object v1

    const-class v3, Lcom/fasterxml/jackson/databind/JsonNode;

    invoke-virtual {v1, v0, v3}, Lcom/instagram/android/service/f;->readValue(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/fasterxml/jackson/databind/JsonNode;

    .line 85
    const-string v1, "result"

    invoke-virtual {v0, v1}, Lcom/fasterxml/jackson/databind/JsonNode;->get(Ljava/lang/String;)Lcom/fasterxml/jackson/databind/JsonNode;

    move-result-object v0

    invoke-virtual {v0}, Lcom/fasterxml/jackson/databind/JsonNode;->asText()Ljava/lang/String;

    move-result-object v0

    invoke-virtual {p1, v0}, Lcom/instagram/pendingmedia/model/c;->h(Ljava/lang/String;)V

    .line 86
    sget-object v0, Lcom/instagram/pendingmedia/model/e;->e:Lcom/instagram/pendingmedia/model/e;

    invoke-virtual {p1, v0}, Lcom/instagram/pendingmedia/model/c;->a(Lcom/instagram/pendingmedia/model/e;)V

    .line 87
    sget-object v0, Lcom/instagram/android/service/aa;->a:Lcom/instagram/android/service/aa;
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_0

    .line 130
    if-eqz v2, :cond_0

    .line 132
    :try_start_5
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getEntity()Lch/boye/httpclientandroidlib/HttpEntity;

    move-result-object v1

    invoke-static {v1}, Lch/boye/httpclientandroidlib/util/EntityUtils;->consume(Lch/boye/httpclientandroidlib/HttpEntity;)V
    :try_end_5
    .catch Ljava/io/IOException; {:try_start_5 .. :try_end_5} :catch_0

    goto :goto_1

    .line 133
    :catch_0
    move-exception v1

    goto :goto_1

    .line 89
    :cond_6
    :try_start_6
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getStatusLine()Lch/boye/httpclientandroidlib/StatusLine;

    move-result-object v0

    invoke-interface {v0}, Lch/boye/httpclientandroidlib/StatusLine;->getStatusCode()I

    move-result v0

    const/16 v6, 0x1a6

    if-ne v0, v6, :cond_7

    .line 91
    const-string v0, "VideoUploader"

    const-string v1, "Video is corrupt? (received 422), failing"

    invoke-static {v0, v1}, Lcom/facebook/e/a/a;->b(Ljava/lang/String;Ljava/lang/String;)V

    .line 94
    invoke-interface {v5}, Ljava/util/Iterator;->remove()V

    .line 96
    sget-object v0, Lcom/instagram/android/service/aa;->c:Lcom/instagram/android/service/aa;
    :try_end_6
    .catchall {:try_start_6 .. :try_end_6} :catchall_0

    .line 130
    if-eqz v2, :cond_0

    .line 132
    :try_start_7
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getEntity()Lch/boye/httpclientandroidlib/HttpEntity;

    move-result-object v1

    invoke-static {v1}, Lch/boye/httpclientandroidlib/util/EntityUtils;->consume(Lch/boye/httpclientandroidlib/HttpEntity;)V
    :try_end_7
    .catch Ljava/io/IOException; {:try_start_7 .. :try_end_7} :catch_1

    goto/16 :goto_1

    .line 133
    :catch_1
    move-exception v1

    goto/16 :goto_1

    .line 98
    :cond_7
    :try_start_8
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getStatusLine()Lch/boye/httpclientandroidlib/StatusLine;

    move-result-object v0

    invoke-interface {v0}, Lch/boye/httpclientandroidlib/StatusLine;->getStatusCode()I

    move-result v0

    const/16 v6, 0x193

    if-ne v0, v6, :cond_8

    .line 100
    const-string v0, "VideoUploader"

    const-string v1, "Received 403, retrying media creation"

    invoke-static {v0, v1}, Lcom/facebook/e/a/a;->b(Ljava/lang/String;Ljava/lang/String;)V

    .line 101
    const/4 v0, 0x0

    invoke-virtual {p1, v0}, Lcom/instagram/pendingmedia/model/c;->a(Ljava/util/List;)V

    .line 102
    sget-object v0, Lcom/instagram/pendingmedia/model/e;->a:Lcom/instagram/pendingmedia/model/e;

    invoke-virtual {p1, v0}, Lcom/instagram/pendingmedia/model/c;->a(Lcom/instagram/pendingmedia/model/e;)V

    .line 103
    sget-object v0, Lcom/instagram/android/service/aa;->b:Lcom/instagram/android/service/aa;
    :try_end_8
    .catchall {:try_start_8 .. :try_end_8} :catchall_0

    .line 130
    if-eqz v2, :cond_0

    .line 132
    :try_start_9
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getEntity()Lch/boye/httpclientandroidlib/HttpEntity;

    move-result-object v1

    invoke-static {v1}, Lch/boye/httpclientandroidlib/util/EntityUtils;->consume(Lch/boye/httpclientandroidlib/HttpEntity;)V
    :try_end_9
    .catch Ljava/io/IOException; {:try_start_9 .. :try_end_9} :catch_2

    goto/16 :goto_1

    .line 133
    :catch_2
    move-exception v1

    goto/16 :goto_1

    .line 105
    :cond_8
    :try_start_a
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getStatusLine()Lch/boye/httpclientandroidlib/StatusLine;

    move-result-object v0

    invoke-interface {v0}, Lch/boye/httpclientandroidlib/StatusLine;->getStatusCode()I

    move-result v0

    const/16 v6, 0x1f7

    if-ne v0, v6, :cond_9

    .line 107
    const-string v0, "VideoUploader"

    const-string v6, "Received 503 on video upload, retrying new server"

    invoke-static {v0, v6}, Lcom/facebook/e/a/a;->b(Ljava/lang/String;Ljava/lang/String;)V

    .line 110
    invoke-interface {v5}, Ljava/util/Iterator;->remove()V

    .line 113
    if-ne v1, v11, :cond_c

    .line 114
    sget-object v0, Lcom/instagram/android/service/aa;->c:Lcom/instagram/android/service/aa;
    :try_end_a
    .catchall {:try_start_a .. :try_end_a} :catchall_0

    .line 130
    if-eqz v2, :cond_0

    .line 132
    :try_start_b
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getEntity()Lch/boye/httpclientandroidlib/HttpEntity;

    move-result-object v1

    invoke-static {v1}, Lch/boye/httpclientandroidlib/util/EntityUtils;->consume(Lch/boye/httpclientandroidlib/HttpEntity;)V
    :try_end_b
    .catch Ljava/io/IOException; {:try_start_b .. :try_end_b} :catch_3

    goto/16 :goto_1

    .line 133
    :catch_3
    move-exception v1

    goto/16 :goto_1

    .line 117
    :cond_9
    :try_start_c
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getStatusLine()Lch/boye/httpclientandroidlib/StatusLine;

    move-result-object v0

    invoke-interface {v0}, Lch/boye/httpclientandroidlib/StatusLine;->getStatusCode()I

    move-result v0

    const/16 v6, 0x1f4

    if-ne v0, v6, :cond_c

    .line 119
    const-string v0, "VideoUploader"

    const-string v6, "Received 500 on video upload, retrying new server"

    invoke-static {v0, v6}, Lcom/facebook/e/a/a;->b(Ljava/lang/String;Ljava/lang/String;)V

    .line 122
    invoke-interface {v5}, Ljava/util/Iterator;->remove()V

    .line 125
    if-ne v1, v11, :cond_c

    .line 126
    sget-object v0, Lcom/instagram/android/service/aa;->c:Lcom/instagram/android/service/aa;
    :try_end_c
    .catchall {:try_start_c .. :try_end_c} :catchall_0

    .line 130
    if-eqz v2, :cond_0

    .line 132
    :try_start_d
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getEntity()Lch/boye/httpclientandroidlib/HttpEntity;

    move-result-object v1

    invoke-static {v1}, Lch/boye/httpclientandroidlib/util/EntityUtils;->consume(Lch/boye/httpclientandroidlib/HttpEntity;)V
    :try_end_d
    .catch Ljava/io/IOException; {:try_start_d .. :try_end_d} :catch_4

    goto/16 :goto_1

    .line 133
    :catch_4
    move-exception v1

    goto/16 :goto_1

    .line 130
    :catchall_0
    move-exception v0

    if-eqz v2, :cond_a

    .line 132
    :try_start_e
    invoke-interface {v2}, Lch/boye/httpclientandroidlib/HttpResponse;->getEntity()Lch/boye/httpclientandroidlib/HttpEntity;

    move-result-object v1

    invoke-static {v1}, Lch/boye/httpclientandroidlib/util/EntityUtils;->consume(Lch/boye/httpclientandroidlib/HttpEntity;)V
    :try_end_e
    .catch Ljava/io/IOException; {:try_start_e .. :try_end_e} :catch_5

    .line 134
    :cond_a
    :goto_4
    throw v0

    .line 141
    :cond_b
    invoke-virtual {p1, v3}, Lcom/instagram/pendingmedia/model/c;->a(Ljava/util/List;)V

    .line 142
    sget-object v0, Lcom/instagram/pendingmedia/model/e;->a:Lcom/instagram/pendingmedia/model/e;

    invoke-virtual {p1, v0}, Lcom/instagram/pendingmedia/model/c;->a(Lcom/instagram/pendingmedia/model/e;)V

    .line 143
    sget-object v0, Lcom/instagram/android/service/aa;->c:Lcom/instagram/android/service/aa;

    goto/16 :goto_1

    .line 133
    :catch_5
    move-exception v1

    goto :goto_4

    :catch_6
    move-exception v4

    goto/16 :goto_3

    :catch_7
    move-exception v1

    goto/16 :goto_1

    :cond_c
    move v0, v4

    goto/16 :goto_2
.end method
